# 启动脚本！
import os

from Functions import *
from Logging import logger


def launcher_playing_vanilla(config_: list):
    """
    此函数用于创建子线程启动Minecraft。
    :param config_: 以元组形式，先后输入：[0]Java版本，[1]游戏版本，[2]最大内存，[3]最小内存，[4]玩家名，[5]玩家uuid。
    :return: 此函数无论是否顺利执行都不返回值。
    """
    launch_java_path = ""
    info_java_version = config_[0]
    info_game_version = config_[1]
    info_max_memory = config_[2]
    info_min_memory = config_[3]
    info_player_name = config_[4]
    info_player_uuid = config_[5]

    java_list = func.get_java_info(0)
    for i in java_list:
        if info_java_version == i['version']:
            launch_java_path = i['path']
    if not launch_java_path:
        logger.Logger.warning("指定Java版本不存在。")
        return None
    back_info = func.get_version_info(0, info_game_version)
    if not back_info:
        logger.Logger.warning("指定Minecraft版本不存在。")
        return None

    info_version_name = back_info[0]
    info__minecraft_path = back_info[1]
    info_assets_path = info__minecraft_path + r"\assets"
    info_version_json_path = back_info[2]
    info_natives_path = back_info[3]
    info_libraries_path = back_info[4]
    info_minecraft_jar_path = back_info[5]
    info_Djava_libraries = back_info[6]
    info_Dminecraft_path = back_info[7]

    get_libraries_json_package = [info_version_name, info_version_json_path, info_libraries_path, info_minecraft_jar_path, info_natives_path]
    java_setting_package = [info_max_memory, info_min_memory, info_Djava_libraries, info_Dminecraft_path]
    get_player_info_package = [info_version_json_path, info_player_name, info_player_uuid, info__minecraft_path, info_assets_path]

    result = '"' + launch_java_path + '" ' \
             + using.java_setting(0, java_setting_package) + " -cp " \
             + using.get_libraries_json(0, get_libraries_json_package) + " " \
             + using.get_player_info(0, get_player_info_package)
    logger.Logger.debug("成功输出启动脚本：" + result)
    logger.Logger.info("启动脚本已输出，准备启动。")
    func.threading_manager.acquire()
    threading.Thread(target=os.system, args=(result,), name="Os_cmd_launcher").start()
    func.threading_manager.release()



